<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="password" placeholder="请输入密码">
    <button>显示密码</button>

    <script>
        var input = document.querySelector('input');
        var btn = document.querySelector('button');
        var open = false;
        btn.onclick = function () {
            if (open) {
                input.type = 'password';
                this.innerHTML = '显示密码';
                open = false;
            } else {
                input.type = 'text';
                this.innerHTML = '隐藏密码';
                open = true;
            }

        }
    </script>
</body>

</html>